// pages/collection/collection.js
let app = getApp();
let testAddr = app.globalData.testAddr;
Page({

  /**
   * 页面的初始数据
   */
  data: {
    guestID: "",
    pageSize: "10",
    pageIndex: "1",
    orderType:"1",
    collections:[],
    tags: [{ id: "1", logname: "询价收藏", imgPath:"enquiry" },
      { id: "2", logname: "报价收藏" ,imgPath:"offer"},
      { id: "3", logname: "公司收藏", imgPath: "logo" }, ],
    tagIndex:1,
    imgPath:"enquiry",  
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.queryCollection();
  },
  queryCollection(){
    let that = this;
    let user = wx.getStorageSync("list");
    console.log(JSON.stringify(user));
    that.setData({
      guestID: user.guestid
    });
    app.util.request({
      url: testAddr + "ordercollect/getCollectByGuest?guestID=55&pageSize=" + that.data.pageSize + "&pageIndex=" + that.data.pageIndex + "&orderType=" + that.data.tagIndex,
      method: "POST",
      success: function (res) {
        console.log(JSON.stringify(res.data));
        that.setData({
          collections: that.data.collections.concat(res.data)
        });
      },
      fail: function (res) {

      },
      complete: function (res) {

      },
    });
  },
  selectTag(event){
    let index = event.currentTarget.dataset.id;
    let path = event.currentTarget.dataset.path;
    this.setData({
      pageIndex:1,
      tagIndex:index,
      imgPath:path,
      collections:[]
    });
    this.queryCollection();
  },
  deleteCollect(){

  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    let that = this;
    that.setData({
      pageIndex: that.data.pageIndex + 1
    });
    console.log(that.data.pageIndex);
    that.queryCollection();
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  }
})